package com.netease.nie.facade;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.SpringBootApplicationContextUtils;
import com.netease.nie.dto.BannerDto;
import com.netease.nie.strategy.AbstractBannerStrategy;
import com.netease.nie.strategy.BannerContext;
import com.netease.nie.strategy.BannerCustomConditionStrategy;
import com.netease.nie.strategy.BannerNoConditionStrategy;

/**
 * 
 * @author wwbn3695
 * @createDate July 2nd,2016
 *
 */
@Service
public class BannerFacadeImpl implements BannerFacade {

	@Autowired
	private BannerContext context;
	
	public List<BannerDto> listBannerDtoByPosition(Long userId, int position) {
		if (userId == null) {
			AbstractBannerStrategy bannerNoConditionStrategy = SpringBootApplicationContextUtils
					.getBean(BannerNoConditionStrategy.class);
			context.setBannerStrategy(bannerNoConditionStrategy);
		} else {
			AbstractBannerStrategy bannerCustomConditionStrategy = SpringBootApplicationContextUtils
					.getBean(BannerCustomConditionStrategy.class);
			context.setBannerStrategy(bannerCustomConditionStrategy);
		}
		List<BannerDto> bannerDtos = context.listBannerDtoByPosition(userId, position);
		return bannerDtos;
	}

}